using UnityEngine;

public class SlimeStunnedState : EnemyState
{
    private Slime slime => (Slime)base.Enemy;

    public SlimeStunnedState(Enemy enemy, string animName) : base(enemy, animName) { }

    public override void Enter()
    {
        base.Enter();
        if (slime.CounterImage.activeSelf)
        {
            slime.CloseCounterAttackWindow();
        }
        slime.Fx.InvokeRepeating("RedColorBlink", 0, 0.1f);
        stateTimer = slime.stunnedDuration;
        Rb.velocity = new Vector2(-slime.FacingDirection * slime.stunnedDirection.x, slime.stunnedDirection.y);
    }

    public override void Update()
    {
        base.Update();
        if (Rb.velocity.y < 0.1f && slime.IsGroundDetected())
        {
            slime.Fx.Invoke("CancelColorChange", 0);
            slime.Anim.SetTrigger("stunFold");
            slime.Stats.MakeInvincible(true);
        }
        if (stateTimer <= 0)
        {
            StateMachine.ChangeTo(slime.IdleState);
        }
    }

    public override void Exit()
    {
        base.Exit();
        slime.Stats.MakeInvincible(false);
    }
}
